package com.cloudcc.mobile.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
/**
 * 判断是否升级类
 * @author Administrator
 *
 */
public class PackageUtils {
	private Context context;
	private PackageManager manager;
	private PackageInfo info;
	public PackageUtils(Context context){
		this.context=context;
		init();
	}
	/**
	 * 初始化数据
	 */
	public void init(){
		manager=context.getPackageManager();
		try {
			info=manager.getPackageInfo(context.getPackageName(),
					PackageManager.GET_ACTIVITIES);
		} catch (NameNotFoundException e) {
			Tools.handle(e);
		}
	}
	/**
	 * 获取版本号
	 */
	public int getVersionCode(){
		return info.versionCode;
	}
	/**
	 * 获取版本名字
	 */
	public String getVersionName(){
		return info.versionName;
	}

	/**
	 * 判断是否升级
	 * @param oldVersion
	 * @param newVersion
	 * @return
	 */
	public boolean isUpgradeVersion(int oldVersion,int newVersion){
		boolean flag=false;
		flag=newVersion>oldVersion?true:false;
		return flag;
	}
}
